package doc2db.interfaces.printer;

import doc2db.Keey;
import doc2db.fileWorker.FileBeginer;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *  Диалог элюстрирующий прогрес печяти 
 * @author yura
 */
class ActDial extends JDialog {

    boolean b = false;
    private Thread fT;

    public ActDial(Thread t) {
        super((JFrame) null, "print", true);
        fT = t;

        JPanel p = new JPanel(new BorderLayout());

        JLabel l = new JLabel("Print " + 0 + " page");
        JLabel l2 = new JLabel(new ImageIcon(FileBeginer.resurse_resurseFolderPane
                + Keey.sp + "Printer.png"));
        Box bb = Box.createHorizontalBox();
        bb.add(l2);
        bb.add(Box.createHorizontalStrut(4));
        bb.add(l);

        p.add(bb, BorderLayout.CENTER);
        setContentPane(p);

        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        setSize(240, 160);
        setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 70,
                Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 120);
        setResizable(false);

        try {
            setIconImage(ImageIO.read(new File(FileBeginer.resurse_resurseFolderMenu
                    + Keey.sp + "Printer.png")));
        } catch (IOException ex) {
        }

        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                int k = JOptionPane.showConfirmDialog(null, "stop ?", "stop ?",
                        JOptionPane.OK_CANCEL_OPTION);
                if (k == JOptionPane.OK_OPTION) {
                    fT.stop();
                    fT = null;
                    setVisible(false);
                }
            }
        });
    }

    public void setText(int i) {
        JPanel p = new JPanel(new BorderLayout());
        JLabel l = new JLabel("Print " + (i + 1) + " page");
        JLabel l2 = new JLabel(new ImageIcon(FileBeginer.resurse_resurseFolderPane
                + Keey.sp + "Printer.png"));
        Box bb = Box.createHorizontalBox();
        bb.add(l2);
        bb.add(Box.createHorizontalStrut(10));
        bb.add(l);
        p.add(bb, BorderLayout.CENTER);
        setContentPane(p);

        if (b) {
            setSize(240, 160);
        } else {
            setSize(241, 160);
        }
        b = !b;

    }
}

